package org.pluslibs.commons.domplus;


import org.apache.commons.lang.StringUtils;


public class HtmlUtils {

	private static final String HEADING = "<h%d>%s</h%s>\n";
	public static final String PARAGRAPH = "<p>%s</p>\n";
	public static final String LIST = "<li>%s</li>\n";
	public static final String UNORDERED_LIST = "<ul>\n%s</ul>";
	public static final String LINK = "<a href=\"%s\">%s</a>";
	
	public static String generateHeading(String header, int headerLevel) {
		return String.format(HEADING, headerLevel, header, headerLevel);
	}
	
	public static String generateParagraph(String str) {
		return generateParagraph(str, true);
	}
	
	public static String generateParagraph(String str, boolean convertNewLines) {
		String paragraph = StringUtils.stripToEmpty(str);
		if(convertNewLines){
			paragraph = convertNewLines(paragraph);
		}
		return String.format(PARAGRAPH,paragraph);
	}

	private static String convertNewLines(String paragraph) {
		return paragraph.replaceAll("\n", "<br/>");
	}

	public static String generateLi(String text) {
		return String.format(LIST, text);
	}
	
	public static String generateUl(String text) {
		return String.format(UNORDERED_LIST, text);
	}
	
	public static String generateLink(String url, String text) {
		return String.format(LINK, url,text);
	}

}
